package com.ftg.product.shangpin.controller;


import com.ftg.product.shangpin.page.PageBean;
import com.ftg.product.shangpin.pojo.Nongchang;
import com.ftg.product.shangpin.pojo.Shangpin;
import com.ftg.product.shangpin.service.ShangpinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/shangpin")
public class ShangpinController {
    @Autowired
    ShangpinService shangpinservice;
    @GetMapping("/show")
    public Map<String,Object> show(HttpServletRequest request){
        Map<String,Object> map=new HashMap<>();
        PageBean pageBean=new PageBean();
        Shangpin shangpin=new Shangpin();
        pageBean.setRequest(request);
        List<Shangpin> list=shangpinservice.show(shangpin,pageBean);
        map.put("code","0");
        map.put("data",list);
        map.put("count",pageBean.getTotal());//总页数
        //map.put("limit",pageBean.getRows());
       // map.put("page",pageBean.getPage());
        return map;
    }


    @PostMapping("/insert")
    public int insert(@RequestBody Shangpin shangpin){
        List<Nongchang> q=shangpinservice.showClazzList();
        //if(q==0) {
           // out.print("{code:0,msg:\"您的操作已成功\"}");
       // }
//	out.print("{code:1001,msg:\"操作失败!!\"}");
       // out.close();
        return  shangpinservice.insert(shangpin);
    }
    @PostMapping("/shows")
    public Map<String,Object> showClazzList(){
        List<Nongchang> list = shangpinservice.showClazzList();
        Map<String,Object> map=new HashMap<>();
        map.put("code","0");
        map.put("msg","");
        map.put("d1",list);
        return map;
    }
}
